package cn.slipi.common.listener;

import cn.slipi.common.utils.cache.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisListener implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        String result = redisUtil.set("sc-redis-listener", "ok", 0);
        if ("OK".equals(result)) {
            log.info("redis 连接成功!!!");
        } else {
            log.error("redis 连接失败...请检查缓存是否开启!!!");
        }
    }
}
